﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _2023_09_13
{
    public partial class Program
    {
        private static void Main6(string[] args)
        {
            int[,] array = new int[4, 2] { { 10, 9 }, { 8, 7 }, { 6, 5 }, { 4, 1 } };
            int res;
            // 陪伴人数
            int k = 1;
            List<int> list = new List<int>();
            List<int> listIndex = new List<int>();
            IEnumerable<int> enumerable = Enumerable.Range(1, array.GetLength(0));
            List<int> asList = enumerable.ToList();
            List<List<int>> result = Pick(asList.ToArray(), k);

            for (int i = 0; i < array.GetLength(0); i++)
            {
                res = CalculateMaxSum(array, result[i]);
                list.Add(res);
            }
            int answer = list.Max();
            Console.WriteLine(answer);
        }

        public static int CalculateMaxSum(int[,] array, List<int> arr)
        {
            int sum = 0;
            for (int index = 0; index < array.GetLength(0); index++)
            {
                if (arr.Exists(t => index == t))
                {
                    sum += array[index, 0];
                }
                else
                {
                    sum += array[index, 1];
                }
            }
            return sum;
        }

        private static List<List<int>> Pick(int[] nums, int m)
        {
            List<List<int>> result = new List<List<int>>();
            List<int> combination = new List<int>();

            Backtrack(result, combination, nums, m, 0);

            return result;
        }

        private static void Backtrack(List<List<int>> result, List<int> combination, int[] nums, int m, int start)
        {
            if (combination.Count == m)
            {
                result.Add(new List<int>(combination));
                return;
            }

            for (int i = start; i < nums.Length; i++)
            {
                combination.Add(nums[i]);
                Backtrack(result, combination, nums, m, i + 1);
                combination.Remove(nums[i]);
            }
        }
    }
}
